<?php
    /**
     * Created by JetBrains PhpStorm.
     * User: akrug
     * Date: 31.05.12
     * Time: 10:25
     * To change this template use File | Settings | File Templates.
     */
    class Model_DbTables_User_Userproject extends Zend_Db_Table_Abstract{

        protected $_name = 'fe_userprojects';

        public function init(){

        }


        /**
         *  Projekt vom User speichern
         */
        public function setUserProject($data, $userId){

            $dbData['fe_userprojects_name']      = $data['fe_userprojects_name'];
            $dbData['fe_userprojects_json']      = $data['fe_userprojects_json'];
            $dbData['fe_userprojects_thumbs']    = "";
            $dbData['fe_user_nid']               = $userId;
            $dbData['fe_userprojects_deleted']   = 0;
            $dbData['fe_userprojects_modified']  = strftime("%Y-%m-%d %H:%M:%S");
            $dbData['fe_userprojects_created']   = strftime("%Y-%m-%d %H:%M:%S");

            $this->insert($dbData);

        }


        public function getUserProjects( $userId){

            $select = $this->select()->where("fe_user_nid = '".$userId."' AND fe_userprojects_hidden = 0 AND fe_userprojects_deleted = 0");

            return  $this->fetchAll($select)->toArray();

        }


        public function deleteUserProjects($userId, $projectId){

            $this->delete("fe_user_nid = '".$userId."' AND fe_userprojects_nid = '".$projectId."'");

        }


    }